package com.systemsjr.mpf;

import android.content.Context;
import android.content.Intent;

import com.systemsjr.mpf.account.AccountInstanceList;
import com.systemsjr.mpf.account.ManageAccountActivity;
import com.systemsjr.mpf.account.ManageAccountInstanceActivity;
import com.systemsjr.mpf.expense.ExpenseList;
import com.systemsjr.mpf.expense.ExpenseTypeList;
import com.systemsjr.mpf.expense.ManageExpenseActivity;
import com.systemsjr.mpf.expense.ManageExpenseTypeActivity;

public class IntentHandler {

	static Intent expenseIntent, expenseListIntent, accountIntent,
			accountListIntent, expenseTypeIntent, expenseTypeListIntent,
			accountInstanceIntent, accountInstanceListIntent;

	public static Intent handleOnOptionsItemSelected(Object packageContext,
			int itemId) {

		Intent intent = null;

		switch (itemId) {
		case R.id.expense_management:

			//if (expenseIntent == null) {
				expenseIntent = startActivity((Context) packageContext,
						ManageExpenseActivity.class);
			//}

			intent = expenseIntent;

			break;
		case R.id.expense_list:
			
			//if (expenseListIntent == null) {
				expenseListIntent = startActivity((Context) packageContext,
						ExpenseList.class);
			//}

			intent = expenseListIntent;
			
			break;
		case R.id.expense_type_management:
			//if (expenseTypeIntent == null) {
				expenseTypeIntent = startActivity((Context) packageContext,
						ManageExpenseTypeActivity.class);
			//}

			intent = expenseTypeIntent;
			
			break;
			
		case R.id.expense_type_list:
			//if (expenseTypeListIntent == null) {
				expenseTypeListIntent = startActivity((Context) packageContext,
						ExpenseTypeList.class);
			//}

			intent = expenseTypeListIntent;
			break;
			
		case R.id.account_instance_management:
			//if (accountInstanceIntent == null) {
				accountInstanceIntent = startActivity((Context) packageContext,
						ManageAccountInstanceActivity.class);
			//}

			intent = accountInstanceIntent;
			break;
		case R.id.account_instance_list:
			//if (accountInstanceListIntent == null) {
				accountInstanceListIntent = startActivity((Context) packageContext,
						AccountInstanceList.class);
			//}

			intent = accountInstanceListIntent;
			break;
			
		case R.id.account_list:
			//if (accountListIntent == null) {
				accountListIntent = startActivity((Context) packageContext,
						MpfActivity.class);
			//}

			intent = accountListIntent;
			break;
		case R.id.account_management:
			//if (accountIntent == null) {
				accountIntent = startActivity((Context) packageContext,
						ManageAccountActivity.class);
			//}

			intent = accountIntent;
			break;
			
		case R.id.app_exit:
			System.exit(0);
			break;
		}
		return intent;
	}

	private static Intent startActivity(Context packageContext, Class<?> cls) {
		return new Intent(packageContext, cls);

	}

}
